package com.healthcloud.controller.modules.instrument;

import com.healthcloud.entity.HlHospitalEntity;
import com.healthcloud.entity.RegionalDisease.ChronicGroupEnity;
import com.healthcloud.service.RegionalDisease.TestprojectitemmonitorService;
import com.healthcloud.thread.MyThread;
import com.healthcloud.thread.MyThread1;
import com.healthcloud.thread.MyThread2;
import com.healthcloud.utils.ApiRes;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * Created by admin on 2018/6/12.
 */
@ApiIgnore
@Controller
@RequestMapping(value = "/regionalDisease")
public class RegionalDiseaseController {

    @Autowired
    private TestprojectitemmonitorService testprojectitemmonitorService;

    @RequestMapping(value = "/list")
    public String tosearch() {

        return "newframe/impl/impl";
    }

    @RequestMapping(value = "/showHospital", method = RequestMethod.GET)
    public @ResponseBody
    ApiRes showHospital(@Param("testKindCode") String testKindCode, @Param("year") String year, @Param("areaCode") String areaCode, @Param("level") String level, Model model) {
        List<HlHospitalEntity> list = testprojectitemmonitorService.showHospital(testKindCode, year,
                Long.valueOf(areaCode), level);
        return new ApiRes(true, list, null, null);
    }

    @RequestMapping(value = "/showList", method = RequestMethod.GET)
    public @ResponseBody
    ApiRes showList(@Param("testKindCode") String testKindCode, @Param("year") String year, Model model, @Param("hospId") String hospId) {

        ChronicGroupEnity chronicGroupEnity = new ChronicGroupEnity();
        chronicGroupEnity.setSlowDiseaseStatisticsEntitys(
                testprojectitemmonitorService.showMonitor(testKindCode, year, hospId));
        chronicGroupEnity.setSlowDiseaseStatisticsVos(
                testprojectitemmonitorService.showTitle(testKindCode, year, null, null, hospId));
        return new ApiRes(true,chronicGroupEnity,null,null);

    }

    @RequestMapping(value = "/areacode", method = RequestMethod.GET)
    @ResponseBody
    public ChronicGroupEnity quearyAreaCode(@Param("testKindCode") String testKindCode, @Param("year") String year, @Param("areaCode") String areaCode, @Param("level") String level) throws Exception{

        long currentTime = System.currentTimeMillis();

        ExecutorService executor = Executors.newFixedThreadPool(100);
        ChronicGroupEnity enity = new ChronicGroupEnity();

        Future<ChronicGroupEnity> future = executor.submit(new MyThread(enity, testKindCode, year, areaCode, level), enity);
        future.get();

        Future<ChronicGroupEnity> future1 = executor.submit(new MyThread1(enity, testKindCode, year, areaCode, level), enity);
        future1.get();

        Future<ChronicGroupEnity> future2 = executor.submit(new MyThread2(enity, testKindCode, year, areaCode, level), enity);
        future2.get();

        System.out.println("运行时间为：" + (System.currentTimeMillis() - currentTime));
        return  enity;

    }
}
